package com.Utility;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.ProgressBar;

import com.dialogs.LoadingDialog;
import com.parser.Error_Report;
import com.parser.Parser_Soap;
import com.senditcertified.mail.R;
import com.soap.call.Http_Soap_Call;

public class UserTokenExpire extends AsyncTask<String, Void, Boolean> {
	private Activity mActivity;
	private ProgressDialog mDialog;
	boolean result = false;
	// String error_msg = "";
	String Result = null;
	Parser_Soap parse = new Parser_Soap();
	Error_Report repor = new Error_Report();

	public UserTokenExpire(Activity mContext) {
		this.mActivity = mContext;
	}

	protected Boolean doInBackground(String... params) {
		Http_Soap_Call call = Http_Soap_Call.create_connection("", mActivity);
		if (call != null) {
			Result = parse.GetLoginTokenExpire(call.GetLoginToken_Expire(
					Utility.getStringPreference(mActivity, "LoginToken", "1"),
					repor), repor);
			if (Result != null) {
				System.out.println("true");
				if (Result.contains("Password Error")) {
					result = false;
				} else {
					result = true;
				}

			} else {
				// error_msg=Utility.INVALID_USER;
				System.out.println("false");
				result = false;
				repor.setMessage("Internal Error");
			}

		} else {
			repor.setMessage(Utility.NETWORK_ISSUE);
			return false;
		}

		return result;
	}

	protected void onPreExecute() {
		if (mDialog != null) {
			mDialog.dismiss();
			mDialog = null;
		}
		mDialog = ProgressDialog.show(mActivity, null,
				mActivity.getString(R.string.loader));
	}

	protected void onPostExecute(Boolean result) {
		// This method runs in the UI thread
		if (mDialog != null) {
			mDialog.dismiss();
			mDialog = null;
		}
		if (result) {
			// Utility.printLog("Login Responce", "Login successfully");
			// Utility.setStringPreference(getParent(), "LoginToken",
			// Result);
			// new User_GetUserInbox().execute(Password);
			/*
			 * Intent mainIntent = new Intent(Password.this,
			 * TabHome_Activity.class); Password.this.startActivity(mainIntent);
			 * Password.this.finish();
			 */
			// Toast.makeText(Password.this, "Login token get",
			// Toast.LENGTH_SHORT)
			// .show();
			mActivity.finish();
		} else {
			// Utility.printLog("Login Responce", "Login Unsuccessfully");
			// Toast.makeText(Password.this, repor.getMessage(),
			// Toast.LENGTH_SHORT).show();
		}

	}

	@Override
	protected void onCancelled() {
		if (mDialog != null) {
			mDialog.dismiss();
			mDialog = null;
		}
		super.onCancelled();
	}
}